#include<iostream>
#include<iomanip>

using namespace std;

typedef float data_t;

void array_insert(data_t list[], int& space_used, data_t value)
{
  int insertPosition = 0;
  //insertPosition = -1;
  
  // do{
  //   ++insertPosition;
  
  //   cout << "insertPosition: " << insertPosition << endl;
  
  // } while (value > list[insertPosition]
  // 	   && insertPosition != space_used - 1);
  
  while (value > list[insertPosition]
	 && insertPosition != space_used)
    ++insertPosition;
  
  if (value <= list[insertPosition])
    {
      for (int k = space_used - 1; k >= insertPosition; --k)
	list[k+1] = list[k];
      
      list[insertPosition] = value;
    }
  else 
    list[space_used] = value;
  
  ++space_used;
}

int array_find(data_t list[], int& space_used, data_t value)
{
  int found = 0;
  int index;
  for(index = 0; index < space_used; ++index)
    {
      if (list[index] == value)
	{
	  //found = 1;
	  //break;
	  return index;
	}
    }
  //if(found)
  //return index;
  //else
    return -1;
}

void array_remove(data_t list[], int& space_used, int index)
{
  for (int i = index; i < space_used; ++i)
    list[i] = list[i+1];
  
  --space_used;
}

void array_copy(data_t dst_list[], data_t src_list[], 
                int& dst_space_used, int src_space_used)
{
  dst_space_used = 0;
  
  for(int i = 0; i < src_space_used; ++i){
    dst_list[i] = src_list[i];
    ++dst_space_used;
  }
}

void array_print(ostream& out, data_t list[], int space_used)
{
  for(int i = 0; i < space_used; ++i)
    cout << list[i] << " ";
  cout << endl;
}
